home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / tlx_sq21.zip / GETNAME.SLT < prev    next >
Text File  |  1992-03-20  |  12KB  |  336 lines

  1. //-----------------------------------------------------------
  2. // GETNAME.SL? Get variables from the NAME.DAT file.
  3. //-----------------------------------------------------------
  4.  
  5. // If you have suggestions for improving this script, please suggest
  6. // improvements to me via old-fashioned snail-mail to:
  7.  
  8. // Author:  Inge Vabekk
  9. //          Hamangskogen 108
  10. //          N-1300 SANDVIKA
  11. //          NORWAY
  12. //          tel. (472) 546 396
  13.  
  14. str namefile [12]= "NAME.DAT"     // File containing name etc.
  15.    ,fonedir  [12]= "TELIX.FON"    // Default phone directory
  16.    ,global     []= "GLOBAL"       // Name of global script
  17.    ,logon      []= "LOGON"        // Logon script.
  18.    ,passw      []= "PASSWORD"     // Password script.
  19.    ,escape     []= "ESCAPE"       // Name of ESCAPE script
  20.    ,cputl      []= "PUTLINE"      // Script to output one line.
  21.    ,join       []= "JOINCONF"     // Join Conference script.
  22.    ,updownf    []= "UPDOWNF"      // Script to send/receive file.
  23.    ,display    []= "DISPLAY"      // Display script.
  24.    ,logoff     []= "LOGOFF"       // Script for auto logoff toggle
  25.    ,prompt     []= "PROMPT"       // Command prompt.
  26.    ,cprot      []= "CPROT"        // Current protocol
  27.    ,maxup      []= "MAXUP"        // Max no. of upload files.
  28.    ,maxdn      []= "MAXDN"        // Max no. of download files.
  29.    ,graph      []= "GRAPH"        // Graphics Y/N.
  30.    ,Aexit      []= "EXIT"         // Auto Exit Y/N
  31.    ,name       []= "NAME"         // Global: User name.
  32.    ,mdir       []= "MDIR"         // Global: Mail directory.
  33.    ,ssl        []= "SSL"          // Status line.
  34.    ,errormess[80]                 // For error message.
  35.    ,inputline[160]                // For reading NAME.DAT file.
  36.    ,varname   [6]
  37.    ;                                     
  38.  
  39. int file                          // File handle
  40.    ,namelen=6                     // Length of names
  41.    ,stringlen=80                  // Max. length of variables
  42.    ;
  43.  
  44. //-----------------------------------------------------------
  45. // Script starts here.
  46. //-----------------------------------------------------------
  47.  
  48. main (int first)
  49. {
  50. int c, i, l;
  51.  
  52. // Check that important scripts are loaded.
  53.  
  54.   if (first == 1)
  55.   { i = load_scripts();
  56.     return (i);
  57.   }
  58. //prints ("T²: Just a moment please....");
  59.  
  60.   write (prompt,"Command");              // Set some defaults.
  61.   write (cprot,"Z");                     // Protocol: Zmodem.
  62.   write (maxup,"10");                    // Max no. for upload.
  63.   write (maxdn,"10");                    // Max no. for download.
  64.   write (graph,"NO");                    // Graphics
  65.   write (Aexit,"NO");                    // Auto Exit.
  66.                                        
  67.   write (prompt," Command");             // Set default command prompt.
  68.  
  69.   if ((file=fopen(namefile,"r"))<=0) 
  70.   { errormess = namefile;
  71.     strcat (errormess," not found!");
  72.     status_wind (errormess,20);          // Show error message.
  73.     return (-1);
  74.   }
  75.  
  76. // Read the NAME.DAT file.
  77.  
  78.   while (fgets(inputline,160,file)>0)    // Get input line.
  79.     codeset ();                          // Find and set the code.
  80.     
  81.   fclose (file);                         // Close the file
  82.  
  83.   read ("Graph",inputline);              // Graphics?
  84.   setchr(inputline,1,0);                 // Set graphics, Y or N.
  85.   strupper(inputline);
  86.   if (inputline != "Y") inputline = "N";
  87.   write ("Graph",inputline);
  88.  
  89.   if (read ("Fdir",errormess) < 0)       // phone directory,
  90.     write ("Fdir",fonedir);
  91.  
  92.   read (mdir,errormess);                 // Mail directory
  93.   for (l=strlen(errormess)-1; l>0; --l)
  94.   { if (subchr(errormess,l) !='\')
  95.       break;
  96.     setchr (errormess,l,0);              // Delete trailing slash.
  97.   }
  98.   exec ("CRDIR",errormess);              // Create directory.
  99.   strcat (errormess,"\");                // Add slash again.
  100.   write (mdir,errormess);                // Set mail directory
  101.   return (0);                            // and return.
  102. }
  103.  
  104. //-----------------------------------------------------------
  105. // Routine to decode one line from the input file.
  106. //-----------------------------------------------------------
  107.  
  108. codeset()
  109. {
  110. int i, k, l, c; 
  111.  
  112.   if ((k=strchr(inputline,0,'{')) >= 0)  // Comment in this line?
  113.   { substr (inputline,k+1,80,errormess); // Move rest to temp.
  114.     setchr (inputline,k,0);              // Truncate here.
  115.     l=strchr(errormess,0,'}');           // End of comment?
  116.     if (l<0)
  117.       setchr (errormess,0,0);            // Not found. All is comment.
  118.     else
  119.       substr (errormess,l+1,80,errormess); // Delete comment.
  120.     strcat (inputline,errormess);        // Add the rest.
  121.   }
  122.  
  123.   k = strchr(inputline,0,'=');           // Find first equal sign.
  124.   if (k < 0) return(0);                  // Not found!
  125.   varname = inputline;                   // Copy to varname.
  126.   if (k<=namelen) 
  127.     setchr (varname,k,0);                // Delete all from '='.
  128.   strcat (varname,"      ");             // Fill with spaces.
  129.  
  130. // Isolate variable. Find first non-space after colon.
  131.  
  132.   while ((c=subchr(inputline,++k))>0)
  133.     if (c > ' ') break;                  // Non-space found.
  134.  
  135.   if (c < ' ') return(0);                // Invalid input.
  136.  
  137.   for (l = strlen(inputline)-1; l>=k; --l)  
  138.     if (subchr(inputline,l) > ' ')       // Remove trailing spaces.
  139.       break;
  140.    
  141.   setchr(inputline,++l,0);               // Insert terminator.
  142.  
  143. // Move string down to start at 0.
  144.  
  145.   substr (inputline,k,stringlen,inputline);
  146.   
  147.   c = subchr(varname,0);                 // Check for key names.
  148.  
  149.   if (toupper(c) =='F')
  150.   { setchr (varname,0,' ');
  151.     i = stoi (varname);
  152.     setchr (varname,0,'F');
  153.  
  154.     if (i > 0 && i < 13)
  155.     { if (strcmpi (inputline,"@name") == 0)  // Replace "@name" by name.
  156.       { if (read (name,inputline) < 0)
  157.           status_wind ("T²: Name is not defined before the user name key!",20);
  158.       }
  159.       if (i == 1)                        // F1 key.
  160.         keyset (0x3b00,0,inputline);
  161.       else if (i == 2)                   // F2 key.
  162.         keyset (0x3c00,0,inputline);
  163.       else if (i == 3)                   // F3 key.
  164.         keyset (0x3d00,0,inputline);
  165.       else if (i == 4)                   // F4 key.
  166.         keyset (0x3e00,0,inputline);
  167.       else if (i == 5)                   // F5 key.
  168.         keyset (0x3f00,0,inputline);
  169.       else if (i == 6)                   // F6 key.
  170.         keyset (0x4000,0,inputline);
  171.       else if (i == 7)                   // F7 key.
  172.         keyset (0x4100,0,inputline);
  173.       else if (i == 8)                   // F8 key.
  174.         keyset (0x4200,0,inputline);
  175.       else if (i == 9)                   // F9 key.
  176.         keyset (0x4300,0,inputline);
  177.       else if (i == 10)                  // F10 key.
  178.         keyset (0x4400,0,inputline);
  179.       else if (i == 11)                  // F11 key.
  180.         keyset (0x8500,0,inputline);
  181.       else if (i == 12)                  // F12 key.
  182.         keyset (0x8600,0,inputline);
  183.       return (0);
  184.     }
  185.   }
  186.   write (varname,inputline);             // Define this global.
  187.   return(0);
  188. }
  189.  
  190. //-----------------------------------------------------------
  191. // Load scripts.
  192. //-----------------------------------------------------------
  193.  
  194. load_scripts()
  195. {
  196.   if (!is_loaded(global))              // Load "Global" script
  197.   { load_scr (global);                 // permanently.
  198.     if (!is_loaded(global))            // Loaded?
  199.     { nosuccess(global);               // No success:
  200.       return (-1);
  201.     }
  202.   }
  203.  
  204.   if (!is_loaded (ssl))                // Load "SSL" script
  205.   { load_scr (ssl);                    // permanently.
  206.     if (!is_loaded(ssl))               // Loaded?
  207.     { nosuccess(ssl);                  // No success:
  208.       return (-1);
  209.     }
  210.   }
  211.  
  212.   if (!is_loaded (escape))             // Load ESCAPE script
  213.   { load_scr (escape);                 // permanently.
  214.     if (!is_loaded(escape))            // Loaded?
  215.     { nosuccess(escape);               // No success:
  216.       return (-1);
  217.     }
  218.   }
  219.  
  220.   if (!is_loaded (cputl))              // Load PUTLINE script
  221.